package com.spark.usermusicService.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.spark.usermusicService.entity.Music;
import com.spark.usermusicService.entity.MusicList;
import com.spark.usermusicService.mapper.JoinMusicMapper;
import com.spark.usermusicService.mapper.MusicListMapper;
import com.spark.usermusicService.service.MusicListService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 歌单中的音乐列表 服务实现类
 * </p>
 *
 * @author wzk
 * @since 2021-07-01
 */
@Service
public class MusicListServiceImpl extends ServiceImpl<MusicListMapper, MusicList> implements MusicListService {

    @Resource
    private JoinMusicMapper mapper;

    public List<MusicList> getMusiclistByPlaylistId(String playlistId) {
        QueryWrapper<MusicList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("playlist_id", playlistId);
        List<MusicList> musicLists = list(queryWrapper);
        return musicLists;
    }

    public List<Music> getMusicDetailsByPlaylistId(String playlistId) {
        List<Music> musicList = mapper.musiclistJoinMusic(playlistId);
        return musicList;
    }

    public boolean deleteAllByPlaylistId(String playlistId) {
        UpdateWrapper<MusicList> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("playlist_id", playlistId);
        return remove(updateWrapper);
    }
}
